from Being import *
from math import sqrt

'''```````````````````````````````````````````````````````````````````````````````````````````````
` Human class, extends Being. Responsible for moving human. See Zombie for details on conversion `
```````````````````````````````````````````````````````````````````````````````````````````````'''

class Human(Being):
	panicked = False
	zombified = False
	color = "#FF1CAE"
	chased_by = 0
	def is_zombie(self):
		return self.zombified
	def move(self):
		if not self.zombified:
			if self.x >= 600 or self.x <= 0 or self.y >= 400 or self.y <= 0:
				#store the previous x and y
				oldx = self.x
				oldy = self.y
				
				#if this being is off of the screen, put them back
				if self.x >= 599:
					self.x = 598
				elif self.x <= 1:
					self.x = 2
				if self.y >= 399:
					self.y = 398
				elif self.y <= 1:
					self.y = 2
				self.canvas.move(self.rectangle, self.x-oldx, self.y-oldy)
			
			
			if self.chased_by == 0:
				#if this human is not chased, just make a random movement
				move_x = randint(-self.speed,self.speed)
				move_y = randint(-self.speed,self.speed)
				
			else:
				#else, move away from the zombie chasing this human
				if self.chased_by.get_x() > self.x:
					move_x = -self.speed
				elif self.chased_by.get_x() < self.x:
					move_x = self.speed
				else:
					move_x = 0
				if self.chased_by.get_y() > self.y:
					move_y = -self.speed
				elif self.chased_by.get_y() < self.y:
					move_y = self.speed
				else:
					move_y = 0
				
			#assume a collision for our first loop
			collision = True
			while(collision):
			
				#not set the collision variable to false, so that if there is no collision, we can escape the loop
				collision = False
				
				for building in self.buildings:
					if building.hit_test(self.x+move_x,self.y+move_y):
						collision = True
						
						#we just hit a building, so move again
						move_x = randint(-self.speed,self.speed)
						move_y = randint(-self.speed,self.speed)
						break
				
				if(not collision):
					#no collision, so break!
					break
					
			#assign our new position
			self.x = self.x + move_x
			self.y = self.y + move_y
			
			#and actually move the rectangle
			self.canvas.move(self.rectangle, move_x, move_y)